package com.shujia.flink.sql

import org.apache.flink.configuration.Configuration
import org.apache.flink.streaming.api.scala.StreamExecutionEnvironment
import org.apache.flink.table.api.EnvironmentSettings
import org.apache.flink.table.api.bridge.scala.StreamTableEnvironment

object Demo7ReadHbase {
  def main(args: Array[String]): Unit = {
    //本地使用的时候增加自定义的参数
    val configuration = new Configuration()
    configuration.setLong("akka.ask.timeout", 100000)

    val bsEnv: StreamExecutionEnvironment = StreamExecutionEnvironment.createLocalEnvironment(1, configuration)


    val bsSettings: EnvironmentSettings = EnvironmentSettings
      .newInstance()
      .useBlinkPlanner() //使用blink计划器
      .inStreamingMode() //使用流模型
      .build()

    //创建flink sql的执行环境
    val bsTableEnv: StreamTableEnvironment = StreamTableEnvironment.create(bsEnv, bsSettings)

    bsTableEnv.executeSql(
      """
        |CREATE TABLE hbase_student (
        | id STRING,
        | info ROW<name STRING,age INT , gender STRING ,clazz STRING>,
        | PRIMARY KEY (id) NOT ENFORCED
        |) WITH (
        | 'connector' = 'hbase-1.4',
        | 'table-name' = 'student',
        | 'zookeeper.quorum' = 'master:2181,node1:2181,node2:2181'
        |)

      """.stripMargin)


    bsTableEnv.executeSql(
      """
        |
        |CREATE TABLE print_table
        |(
        |id STRING,
        |name STRING
        |
        |)
        |WITH ('connector' = 'print')
        |
      """.stripMargin)

    bsTableEnv.executeSql(
      """
        |insert into print_table
        |select id,info.name as name from hbase_student
        |
      """.stripMargin)
  }

}
